<?php
class Admin_advertisements_model extends CI_Model {

	function __construct(){
		parent::__construct();
	}

	function getAdvertisements($where=""){
		$query = $this->db->query("SELECT * FROM mlme_advertisements $where");
		return $query;
	}

	function getAdvertisements_limited($start_row=0, $limit=10){
		$query = $this->db->query("SELECT * FROM mlme_advertisements ORDER BY advertisementsid DESC LIMIT $start_row, $limit");
		return $query->result();
	}

	function addAdvertisements($data){
		$data['date_added'] = date('y-m-d h:m:s');
		$data['date_updated'] = date('y-m-d h:m:s');

		return $this->db->insert('mlme_advertisements', $data);
	}

	function updateAdvertisements($post,$id){
		$post['date_updated'] = date('y-m-d h:m:s');
		 $column = '';
		$column .= !empty($post['banner']) ? '`banner` = "'.$post['banner'].'", ' : null;
		$column .= '`date_updated` = "'.$post['date_updated'].'", ';
		$column .= '`name` = "'.$post['name'].'", ';
		$column .= '`status` = "'.$post['status'].'", ';
		$column .= '`section` = "'.$post['section'].'"';
		$sql = 'UPDATE `mlme_advertisements` SET '.$column.' WHERE advertisementsid="'.$id.'"';
		$query = $this->db->query($sql); 
		return ($query) ? TRUE : FALSE;
		
	}
	
	//delete data
	function deleteAds( $id=array() ){
		if( empty($id) ) return false;
		$this->db->where_in( 'advertisementsid', $id );
		return $this->db->delete('mlme_advertisements');
	}



}// end of Model